package com.kaiwukj.android.ufamily.mvp.ui.page.account.community;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.kaiwukj.android.ufamily.R;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.CommunityResult;

import java.util.ArrayList;

public class CommunityNearAdapter extends BaseQuickAdapter<CommunityResult, BaseViewHolder> {
    public CommunityNearAdapter() {
        super(R.layout.item_community_near, new ArrayList<>());
    }

    @Override
    public long getItemId(int position) {
        CommunityResult item = getItem(position);
        if (item == null) {
            return -1;
        }
        return item.getId();
    }

    @Override
    protected void convert(BaseViewHolder helper, CommunityResult item) {
        helper.setText(R.id.tv_community, item.getCommunityName());
        helper.setText(R.id.tv_address, item.getAddress());
        if (item.getDistance() != null && item.getDistance() > 0) {
            helper.setText(R.id.tv_distance, String.format("%skm", item.getDistanceStr()));
        }
    }
}
